ArchivePanel = Ext.extend(Ext.Panel, {
	constructor : function(config) {
		Ext.apply(this, config);
		this.tree = new Ext.tree.TreePanel({
			region : 'west',
			title : '管理',
			split : true,
			width : 200,
			minSize : 175,
			maxSize : 400,
			collapsible : true,
			layout : 'accordion',
			layoutConfig : {
				animate : true
			},
			autoScroll : true,
			animate : true,
			border : false,
			rootVisible : true,
			root : new Ext.tree.AsyncTreeNode({
				id : "root",
				text : "分类",
				"isWebnewscat" : "false",
				listeners : {
					'click' : function(node, event) {
						node.expand(true);
					}
				},
				loader : new RockyCurd.TreeLoader({
					dataUrl : "generateTree.action",
					expanded : true,
					nodeMeta : {
						id : 'id',
						text : 'name'
					}
				})
			}),
			listeners : {
				'click' : function(node, event) {
					var panel = Ext.getCmp("NewsCurd");
					if (!panel) {
						Ext.MessageBox.alert('操作有误，新闻管理窗口打开失败！');
						return false;
					}
					panel.store.baseParams.newscatid = node.id;
					panel.refresh();
				}
			}
		});
		this.curd = new FamilyCurd();

	}
});
ArchiveCurd = Ext.extend(RockyGridCurd, {
	title : "土地档案管理",
	// layout : "fit",
	// region : "center",
	baseUrl : 'archive.action',
	winCfg : {
		height : 360,
		width : 360,
		maximizable : true,
		title : "详细信息"
	},
	conciseMode : true,
	trackMouseOver : false,
	loadMask : false,
	autoWidth : false,
	autoScroll : true,
	closable : true,
	viewConfig : {
		forceFit : false
	},
	win : null,
	fp : null,
	constructor : function(config) {
		Ext.apply(this, config);
		var sm = new Ext.grid.CheckboxSelectionModel();
		var cmpId = this.id;
		this.keywordFilter = new Ext.form.TextField({
			width : 100,
			pressed : true,
			scope : this
		});		
		this.store = new Ext.data.JsonStore({
			id : "id",
			url : 'family.action',
			listeners : {
				beforeload : function() {
					this.store.baseParams.limit = 20;
					this.store.baseParams.cmd = 'read';					
					this.store.baseParams.suc = 'archiveread';
					var keywordFilterValue = this.keywordFilter.getValue();
					this.store.baseParams.keywordFilterValue = keywordFilterValue || '';
				},
				scope : this
			},			
			root : "data",
			totalProperty : "rowCount",
			remoteSort : false,
			fields : ["archive_photos_size","archive_pics_size","archive_archivePics_size","archive_files_size","area_code","areaid", "area","householdernameR", "id", "memo", "householderid", "familycode", "householdername", "address", "archive_id", "archive_constructionArea", "archive_description", "archive_familyJson", "archive_foundationArea", "archive_id", "archive_keyword", "archive_latest", "archive_snapTime", "archive_status", "archive_type"]
			
		});
		this.cm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), sm, {
//			header : "id_family",
//			sortable : true,
//			width : 60,
//			dataIndex : "id"
//		}, {
//			header : "archive_id",
//			sortable : true,
//			width : 60,
//			dataIndex : "archive_id"
//
//		}, {
//			header : "户主ID",
//			sortable : true,
//			width : 100,
//			renderer : function(v, r) {
//				if (!v || v == "-1") {
//					return "<font color=red>没有关联户主</font>";
//				} else {
//					return v;
//				}
//			},			
//			dataIndex : "householderid"
//		}, {
			header : "户主姓名",
			sortable : true,
			width : 80,
			dataIndex : "householdername"
		}, {
			header : "户主姓名R",
			sortable : true,
			width : 80,
			dataIndex : "householdernameR"
		}, {
			header : "家庭编码",
			sortable : true,
			width : 80,
			dataIndex : "familycode"
		}, {
			header : "自然村编码",
			sortable : true,
			width : 80,
			dataIndex : "area_code"					
		}, {
			header : "所在自然村",
			sortable : true,
			width : 100,
			dataIndex : "area"			
		}, {
			header : "家庭地址",
			sortable : true,
			width : 200,
			dataIndex : "address"
		}, {
			header : "建基面积",
			sortable : true,
			width : 60,
			dataIndex : "archive_foundationArea"
		}, {
			header : "建筑面积",
			sortable : true,
			width : 60,
			dataIndex : "archive_constructionArea"
		}, {
			header : "照片数量",
			sortable : true,
			width : 60,
			renderer : function(v, r) {
				if (v && v != "0") {					
					return v;
				} else {
					return String.format("<font color=red >{0}</a>", v);
				}
			},
			dataIndex : "archive_photos_size"	
		}, {
			header : "图纸数量",
			sortable : true,
			width : 60,
			renderer : function(v, r) {
				if (v && v != "0") {					
					return v;
				} else {
					return String.format("<font color=red >{0}</a>", v);
				}
			},
			dataIndex : "archive_pics_size"	
		}, {
			header : "历史档案数量",
			sortable : true,
			width : 100,
			renderer : function(v, r) {
				if (v && v != "0") {					
					return v;
				} else {
					return String.format("<font color=red >{0}</a>", v);
				}
			},
			dataIndex : "archive_archivePics_size"	
		}, {
			header : "附件数量",
			sortable : true,
			width : 60,
			renderer : function(v, r) {
				if (v && v != "0") {					
					return v;
				} else {
					return String.format("<font color=red >{0}</a>", v);
				}
			},
			dataIndex : "archive_files_size"				
		}, {
			header : "查看档案",
			sortable : true,
			width : 60,
			renderer : function(v, r) {
				if (v && v != "-1") {					
					return String.format("<a href='report.action?id={0}&suc=PDF' target='_blank' class='archivereportlink' >查看档案</a>", encodeURIComponent(v))
				} else {
					return "<font color=red>档案信息不完整</font>";
				}
			},
			dataIndex : "archive_id"		
//		}, {
//			header : "查看档案xls",
//			sortable : true,
//			width : 120,
//			renderer : function(v, r) {
//				if (v && v != "-1") {
//					return String.format("<a href='report.action?id={0}&suc=HTML' target='_blank' >查看档案</a>", v)
//				} else {
//					return "<font color=red>档案信息不完整</font>";
//				}
//			},
//			dataIndex : "archive_id"				
//		}, {
//			header : "查看档案",
//			sortable : true,
//			width : 120,
//			renderer : function(v, r) {
//				if (v && v != "-1") {
//					return String.format("<a href='archiveReport.action?id={0}' target='_blank' >查看档案</a>", v)
//				} else {
//					return "<font color=red>档案信息不完整</font>";
//				}
//			},
//			dataIndex : "archive_id"
		}]);
		this.cm.defaultSortable = true;
		FamilyCurd.superclass.constructor.call(this, {
			sm : sm,
			cm : this.cm,
			store : this.store,
			tbar : ['   ', {
				text : '编辑档案',
				iconCls : 'edit',
				pressed : false,
				handler : this.edit,
				scope : this
			}, '   ', {
				text : '刷新',
				iconCls : 'refresh',
				pressed : false,
				handler : this.refresh,
				scope : this
			}, new Ext.Toolbar.Fill(), '请输入关键字: ', this.keywordFilter, {
				text : '查询',
				iconCls : 'search',
				handler : this.search,
				scope : this
			}, {
				text : '重置',
				iconCls : 'cancel',
				pressed : true,
				handler : this.onReset,
				scope : this
			}, '   '],
			bbar : new Ext.PagingToolbar({
				pageSize : 20,
				store : this.store,
				displayInfo : true,
				displayMsg : '显示{0}-{1}，共{2}条记录',
				emptyMsg : "没有可显示的记录！"
			})
		});
		// this.store.load();
	},
	onReset : function() {
		this.keywordFilter.setValue("");
	},	
	createForm : function() {
		var formPanel = new Ext.form.FormPanel({
					xtype : "form",
					frame : true,
					autoScroll : false,
					border : false,
					title : '基本信息',
					layout : "column",
					bodyStyle : "",
					width : 750,
					height : 300,
					items : [{
						xtype : "fieldset",
						title : "家庭信息:",
						autoHeight : true,
						columnWidth : 0.48,
						style : "margin:10px 0 0 10px",
						border : false,
						defaults : {
							anchor : '98%'
						},
						items : [{
							xtype : "hidden",
							name : "familyid",
							id : "familyid"
						}, {
							xtype : "hidden",
							name : "householderid",
							id : "householderid"
						}, {
							xtype : "textfield",
							fieldLabel : "家庭编码",
							allowBlank : false,
							name : "familycode"
						}, {
							xtype : "textfield",
							fieldLabel : "户主姓名",
							allowBlank : false,
							name : "householdername"
						}, {
							xtype : "textfield",
							fieldLabel : "家庭地址",
							allowBlank : false,
							name : "address"
						}, {
							xtype : "textarea",
							fieldLabel : "备注信息",
							allowBlank : true,
							name : "familymemo",
							height : 100
						}]
					}, {
						xtype : "fieldset",
						title : "土地信息:",
						autoHeight : true,
						columnWidth : 0.48,
						style : "margin:10px 0 0 10px",
						border : false,
						defaults : {
							anchor : '96%'
						},
						items : [{
							xtype : "hidden",
							name : "id",
							id : "id"
						}, {
							xtype : "textfield",
							fieldLabel : "地号",
							allowBlank : false,
							name : "areanum"
						}, {
							xtype : "textfield",
							fieldLabel : "土地证号",
							allowBlank : false,
							name : "areacard"
						}, {
							xtype : "textfield",
							fieldLabel : "审批表号",
							allowBlank : false,
							name : "autonum"
						}, {
							xtype : "textfield",
							fieldLabel : "权属性质",
							allowBlank : false,
							name : "owntype"
						}, {
							xtype : "textfield",
							fieldLabel : "用途",
							allowBlank : false,
							name : "useful"
						}, {
							xtype : "textfield",
							fieldLabel : "占地面积",
							allowBlank : false,
							name : "foundationArea"
						}, {
							xtype : "textfield",
							fieldLabel : "建筑面积",
							allowBlank : false,
							name : "constructionArea"
						}]
					}]
				});
		return formPanel;
	},
	edit : function() {
		var record = this.getSelectionModel().getSelected();
		if (!record) {
			Ext.Msg.alert("提示", "请先选择要编辑的行!");
			return;
		}
		var familyid = record.get("id");
		// this.showWin();
		Ext.Ajax.request({
			url : this.baseUrl,
			params : {
				'cmd' : "updatelink",
				'id' : familyid
			},
			method : 'POST',
			success : function(response) {
				var r = Ext.util.JSON.decode(response.responseText);
				if (!r.success) {
					Ext.Msg.alert("提示信息", "失败，由以下原因所致：<br/>" + (r.errors ? r.errors : "未知原因"));
				} else {
					var archiveid = r.data.id;
					this.fp = this.createForm();// 基本信息
					this.familyMemberGrid = new FamilyMemberGrid({
						title : '家庭成员信息',
						familyid : familyid,
						height : 300,
						width:600,
						archiveid : archiveid
					});
					this.photos = new AttachmentCurd({
						title : '土地照片',
						type : '1',
						width:580,						
						familyid : familyid,
						archiveid : archiveid
					});// 照片
					this.pics = new AttachmentCurd({
						title : '土地图纸',
						type : '2',
						width:580,						
						familyid : familyid,
						archiveid : archiveid
					});// 图纸
					this.archivePics = new AttachmentCurd({
						title : '原始档案',
						type : '3',
						width:580,						
						familyid : familyid,
						archiveid : archiveid
					});// 原始档案
					this.files = new AttachmentCurd({
						title : '备注文件',
						type : '4',
						width:580,						
						familyid : familyid,
						archiveid : archiveid
					});// 附件
					this.win = new Ext.Window({
						title : '土地档案详细信息',
						buttonAlign : "center",
						closeAction : "hide",
						// layout:"fit",
						region : "center",
						width : 760,
						height : 400,
						modal : true,
						shadow : true,
						maximizable : true,
						items : {
							xtype : "tabpanel",
							activeTab : 0,
							defaults : {
								closable : false
							},
							items : [this.fp, this.familyMemberGrid, this.photos, this.pics, this.archivePics, this.files]
						},
						buttons : [{
							text : "保存",
							handler : this.save,
							scope : this
						}, {
							text : "取消",
							handler : this.closeWin,
							scope : this
						}]
					});
					this.win.show();
					this.fp.form.loadRecord(new Ext.data.Record(r.data, archiveid));
				}
			},
			failure : function(Optional) {
				Ext.Msg.alert("提示信息", "连接服务器失败!");
			},
			scope : this
		});

	}
});

// FamilyMemberGrid
FamilyMemberGrid = Ext.extend(RockyGridCurd, {
	title : "家庭成员",
	// layout : "fit",
	// region : "center",
	baseUrl : 'person.action',
	winCfg : {
		height : 360,
		width : 360,
		maximizable : true,
		title : "详细信息"
	},
	conciseMode : true,
	trackMouseOver : false,
	loadMask : false,
	autoWidth : false,
	autoScroll : true,
	closable : true,

	win : null,
	fp : null,	
	

	constructor : function(config) {
		Ext.apply(this, config);
		this.store = new Ext.data.JsonStore({
			id : "id",
			url : 'person.action',
			baseParams : {
				cmd : 'read',
				suc : 'familymembergrid',
				familyid : this.familyid || ''
			},
			root : "data",
			totalProperty : "rowCount",
			remoteSort : false,
			fields : ["householdername", "familyid", "familycode", "area", "areaid", "address", "householder", "householderRelation", "name", "sex", "birthday", "cardnumber", "residenceType", "id"],
			listeners : {
				beforeload : function() {
					this.store.baseParams.limit = 20;
					this.store.baseParams.keywordFilterValue = '';
				},
				scope : this
			}
		});
		var cmpId = this.id;
		this.cm = new Ext.grid.ColumnModel([{
//			header : "id_person",
//			sortable : true,
//			width : 80,
//			dataIndex : "id"
//		}, {			
//			header : "familyid",
//			sortable : true,
//			width : 80,
//			dataIndex : "familyid"
//		}, {
			header : "姓名",
			sortable : true,
			width : 100,
			dataIndex : "name"
		}, {
			header : "性别",
			sortable : true,
			width : 50,
			dataIndex : "sex",
			renderer : function(v) {
				return selectStore(Sex_Store, v);
			}
		}, {
			header : "出生年月",
			sortable : true,
			width : 100,
			dataIndex : "birthday"
		}, {
			header : "身份证号",
			sortable : true,
			width : 200,
			dataIndex : "cardnumber"
		}, {
			header : "户籍类型",
			sortable : true,
			width : 100,
			dataIndex : "residenceType",
			renderer : function(v) {
				return selectStore(Residence_Store, v);
			}			
		}, {
			header : "户主姓名",
			sortable : true,
			width : 100,
			dataIndex : "householdername"			
		}, {
			header : "户主关系",
			sortable : true,
			width : 100,
			dataIndex : "householderRelation",
			renderer : function(v) {
				return selectStore(Relation_Store, v);
			}
		}, {
			header : "住址",
			sortable : true,
			width : 300,
			dataIndex : "address"
		}]);
		this.cm.defaultSortable = true;
		Ext.apply(this, {
			cm : this.cm,
			store : this.store,
			bbar : new Ext.PagingToolbar({
				pageSize : 20,
				store : this.store,
				displayInfo : true,
				displayMsg : '显示{0}-{1}，共{2}条记录',
				emptyMsg : "没有可显示的记录！"
			})
		});
		FamilyMemberGrid.superclass.constructor.call(this, config);
	},
	edit : function() {		
		return false;
	},
	removeData : function() {		
		return false;
	},
	refresh:function(){		
		return false;
	}	
});